
<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta charset="utf-8" />
    <title>Introduction to atomman: Atoms class &#8212; atomman 1.4.0 documentation</title>
    <link rel="stylesheet" href="../_static/basic.css" type="text/css" />
    <link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
    <script type="text/javascript" id="documentation_options" data-url_root="../" src="../_static/documentation_options.js"></script>
    <script type="text/javascript" src="../_static/jquery.js"></script>
    <script type="text/javascript" src="../_static/underscore.js"></script>
    <script type="text/javascript" src="../_static/doctools.js"></script>
    <script type="text/javascript" src="../_static/language_data.js"></script>
    <script crossorigin="anonymous" integrity="sha256-Ae2Vz/4ePdIu6ZyI/5ZGsYnb+m0JlOmKPjt6XZ9JJkA=" type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/require.js/2.3.4/require.min.js"></script>
    <script async="async" type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/latest.js?config=TeX-AMS-MML_HTMLorMML"></script>
    <script type="text/x-mathjax-config">MathJax.Hub.Config({"tex2jax": {"inlineMath": [["$", "$"], ["\\(", "\\)"]], "processEscapes": true, "ignoreClass": "document", "processClass": "math|output_area"}})</script>
    <link rel="index" title="Index" href="../genindex.html" />
    <link rel="search" title="Search" href="../search.html" />
    <link rel="next" title="Introduction to atomman: System class" href="1.3._System_class.html" />
    <link rel="prev" title="Introduction to atomman: Box class" href="1.1._Box_class.html" /> 
  </head><body>
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="1.3._System_class.html" title="Introduction to atomman: System class"
             accesskey="N">next</a> |</li>
        <li class="right" >
          <a href="1.1._Box_class.html" title="Introduction to atomman: Box class"
             accesskey="P">previous</a> |</li>
        <li class="nav-item nav-item-0"><a href="../index.html">atomman 1.4.0 documentation</a> &#187;</li>
          <li class="nav-item nav-item-1"><a href="index.html" accesskey="U">Tutorials</a> &#187;</li> 
      </ul>
    </div>  

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body" role="main">
            
  
<style>
/* CSS for nbsphinx extension */

/* remove conflicting styling from Sphinx themes */
div.nbinput.container div.prompt *,
div.nboutput.container div.prompt *,
div.nbinput.container div.input_area pre,
div.nboutput.container div.output_area pre,
div.nbinput.container div.input_area .highlight,
div.nboutput.container div.output_area .highlight {
    border: none;
    padding: 0;
    margin: 0;
    box-shadow: none;
}

div.nbinput.container > div[class*=highlight],
div.nboutput.container > div[class*=highlight] {
    margin: 0;
}

div.nbinput.container div.prompt *,
div.nboutput.container div.prompt * {
    background: none;
}

div.nboutput.container div.output_area .highlight,
div.nboutput.container div.output_area pre {
    background: unset;
}

div.nboutput.container div.output_area div.highlight {
    color: unset;  /* override Pygments text color */
}

/* avoid gaps between output lines */
div.nboutput.container div[class*=highlight] pre {
    line-height: normal;
}

/* input/output containers */
div.nbinput.container,
div.nboutput.container {
    display: -webkit-flex;
    display: flex;
    align-items: flex-start;
    margin: 0;
    width: 100%;
}
@media (max-width: 540px) {
    div.nbinput.container,
    div.nboutput.container {
        flex-direction: column;
    }
}

/* input container */
div.nbinput.container {
    padding-top: 5px;
}

/* last container */
div.nblast.container {
    padding-bottom: 5px;
}

/* input prompt */
div.nbinput.container div.prompt pre {
    color: #307FC1;
}

/* output prompt */
div.nboutput.container div.prompt pre {
    color: #BF5B3D;
}

/* all prompts */
div.nbinput.container div.prompt,
div.nboutput.container div.prompt {
    width: 4.5ex;
    padding-top: 5px;
    position: relative;
    user-select: none;
}

div.nbinput.container div.prompt > div,
div.nboutput.container div.prompt > div {
    position: absolute;
    right: 0;
    margin-right: 0.3ex;
}

@media (max-width: 540px) {
    div.nbinput.container div.prompt,
    div.nboutput.container div.prompt {
        width: unset;
        text-align: left;
        padding: 0.4em;
    }
    div.nboutput.container div.prompt.empty {
        padding: 0;
    }

    div.nbinput.container div.prompt > div,
    div.nboutput.container div.prompt > div {
        position: unset;
    }
}

/* disable scrollbars on prompts */
div.nbinput.container div.prompt pre,
div.nboutput.container div.prompt pre {
    overflow: hidden;
}

/* input/output area */
div.nbinput.container div.input_area,
div.nboutput.container div.output_area {
    -webkit-flex: 1;
    flex: 1;
    overflow: auto;
}
@media (max-width: 540px) {
    div.nbinput.container div.input_area,
    div.nboutput.container div.output_area {
        width: 100%;
    }
}

/* input area */
div.nbinput.container div.input_area {
    border: 1px solid #e0e0e0;
    border-radius: 2px;
    /*background: #f5f5f5;*/
}

/* override MathJax center alignment in output cells */
div.nboutput.container div[class*=MathJax] {
    text-align: left !important;
}

/* override sphinx.ext.imgmath center alignment in output cells */
div.nboutput.container div.math p {
    text-align: left;
}

/* standard error */
div.nboutput.container div.output_area.stderr {
    background: #fdd;
}

/* ANSI colors */
.ansi-black-fg { color: #3E424D; }
.ansi-black-bg { background-color: #3E424D; }
.ansi-black-intense-fg { color: #282C36; }
.ansi-black-intense-bg { background-color: #282C36; }
.ansi-red-fg { color: #E75C58; }
.ansi-red-bg { background-color: #E75C58; }
.ansi-red-intense-fg { color: #B22B31; }
.ansi-red-intense-bg { background-color: #B22B31; }
.ansi-green-fg { color: #00A250; }
.ansi-green-bg { background-color: #00A250; }
.ansi-green-intense-fg { color: #007427; }
.ansi-green-intense-bg { background-color: #007427; }
.ansi-yellow-fg { color: #DDB62B; }
.ansi-yellow-bg { background-color: #DDB62B; }
.ansi-yellow-intense-fg { color: #B27D12; }
.ansi-yellow-intense-bg { background-color: #B27D12; }
.ansi-blue-fg { color: #208FFB; }
.ansi-blue-bg { background-color: #208FFB; }
.ansi-blue-intense-fg { color: #0065CA; }
.ansi-blue-intense-bg { background-color: #0065CA; }
.ansi-magenta-fg { color: #D160C4; }
.ansi-magenta-bg { background-color: #D160C4; }
.ansi-magenta-intense-fg { color: #A03196; }
.ansi-magenta-intense-bg { background-color: #A03196; }
.ansi-cyan-fg { color: #60C6C8; }
.ansi-cyan-bg { background-color: #60C6C8; }
.ansi-cyan-intense-fg { color: #258F8F; }
.ansi-cyan-intense-bg { background-color: #258F8F; }
.ansi-white-fg { color: #C5C1B4; }
.ansi-white-bg { background-color: #C5C1B4; }
.ansi-white-intense-fg { color: #A1A6B2; }
.ansi-white-intense-bg { background-color: #A1A6B2; }

.ansi-default-inverse-fg { color: #FFFFFF; }
.ansi-default-inverse-bg { background-color: #000000; }

.ansi-bold { font-weight: bold; }
.ansi-underline { text-decoration: underline; }


div.nbinput.container div.input_area div[class*=highlight] > pre,
div.nboutput.container div.output_area div[class*=highlight] > pre,
div.nboutput.container div.output_area div[class*=highlight].math,
div.nboutput.container div.output_area.rendered_html,
div.nboutput.container div.output_area > div.output_javascript,
div.nboutput.container div.output_area:not(.rendered_html) > img{
    padding: 5px;
    margin: 0;
}

/* fix copybtn overflow problem in chromium (needed for 'sphinx_copybutton') */
div.nbinput.container div.input_area > div[class^='highlight'],
div.nboutput.container div.output_area > div[class^='highlight']{
    overflow-y: hidden;
}

/* hide copybtn icon on prompts (needed for 'sphinx_copybutton') */
.prompt a.copybtn {
    display: none;
}

/* Some additional styling taken form the Jupyter notebook CSS */
div.rendered_html table {
  border: none;
  border-collapse: collapse;
  border-spacing: 0;
  color: black;
  font-size: 12px;
  table-layout: fixed;
}
div.rendered_html thead {
  border-bottom: 1px solid black;
  vertical-align: bottom;
}
div.rendered_html tr,
div.rendered_html th,
div.rendered_html td {
  text-align: right;
  vertical-align: middle;
  padding: 0.5em 0.5em;
  line-height: normal;
  white-space: normal;
  max-width: none;
  border: none;
}
div.rendered_html th {
  font-weight: bold;
}
div.rendered_html tbody tr:nth-child(odd) {
  background: #f5f5f5;
}
div.rendered_html tbody tr:hover {
  background: rgba(66, 165, 245, 0.2);
}
</style>
<div class="section" id="Introduction-to-atomman:-Atoms-class">
<h1>Introduction to atomman: Atoms class<a class="headerlink" href="#Introduction-to-atomman:-Atoms-class" title="Permalink to this headline">¶</a></h1>
<p><strong>Lucas M. Hale</strong>, <a class="reference external" href="mailto:lucas&#46;hale&#37;&#52;&#48;nist&#46;gov?Subject=ipr-demo">lucas<span>&#46;</span>hale<span>&#64;</span>nist<span>&#46;</span>gov</a>, <em>Materials Science and Engineering Division, NIST</em>.</p>
<p><a class="reference external" href="http://www.nist.gov/public_affairs/disclaimer.cfm">Disclaimers</a></p>
<div class="section" id="1.-Introduction">
<h2>1. Introduction<a class="headerlink" href="#1.-Introduction" title="Permalink to this headline">¶</a></h2>
<p>The Atoms class collects per-atom properties. The basic behaviors of the class are:</p>
<ul class="simple">
<li><p>The number of atoms is immutable after initializing.</p></li>
<li><p>The only default per-atom properties are an integer atomic type ‘atype’ and 3D position vector ‘pos’.</p></li>
<li><p>Any other per-atom property can be freely assigned of any shape or type.</p></li>
<li><p>When creating a new per-atom property, values must be given for all atoms, and the types must be consistent.</p></li>
</ul>
<p><strong>Note</strong>: The underlying structure of Atoms changed with version 1.2 to be more memory efficient and easier to work with. The methods and attributes were designed with the old versions in mind, but there is no guarantee of complete backwards compatibility.</p>
<p><strong>Library Imports</strong></p>
<div class="nbinput docutils container">
<div class="prompt highlight-none notranslate"><div class="highlight"><pre><span></span>[1]:
</pre></div>
</div>
<div class="input_area highlight-ipython3 notranslate"><div class="highlight"><pre>
<span></span><span class="c1"># Standard Python libraries</span>
<span class="kn">import</span> <span class="nn">datetime</span>

<span class="c1"># http://www.numpy.org/</span>
<span class="kn">import</span> <span class="nn">numpy</span> <span class="k">as</span> <span class="nn">np</span>

<span class="c1"># https://github.com/usnistgov/atomman</span>
<span class="kn">import</span> <span class="nn">atomman</span> <span class="k">as</span> <span class="nn">am</span>

<span class="c1"># Show atomman version</span>
<span class="nb">print</span><span class="p">(</span><span class="s1">&#39;atomman version =&#39;</span><span class="p">,</span> <span class="n">am</span><span class="o">.</span><span class="n">__version__</span><span class="p">)</span>

<span class="c1"># Show date of Notebook execution</span>
<span class="nb">print</span><span class="p">(</span><span class="s1">&#39;Notebook executed on&#39;</span><span class="p">,</span> <span class="n">datetime</span><span class="o">.</span><span class="n">date</span><span class="o">.</span><span class="n">today</span><span class="p">())</span>
</pre></div>
</div>
</div>
<div class="nboutput nblast docutils container">
<div class="prompt empty docutils container">
</div>
<div class="output_area docutils container">
<div class="highlight"><pre>
atomman version = 1.4.0
Notebook executed on 2021-08-03
</pre></div></div>
</div>
</div>
<div class="section" id="2.-Basics">
<h2>2. Basics<a class="headerlink" href="#2.-Basics" title="Permalink to this headline">¶</a></h2>
<div class="section" id="2.1.-Initialization">
<h3>2.1. Initialization<a class="headerlink" href="#2.1.-Initialization" title="Permalink to this headline">¶</a></h3>
<p>Parameters</p>
<ul class="simple">
<li><p><strong>natoms</strong> (<em>int, optional</em>) The number of atoms to associate with the Atoms instance. This is constant once the Atoms object is initialized. If not given, will be inferred from the length of atype and/or pos.</p></li>
<li><p><strong>atype</strong> (<em>int or list of ints, optional</em>) The per-atom integer atomic types. If not given, atype is set to 1 for all atoms.</p></li>
<li><p><strong>pos</strong> (<em>numpy.ndarray, optional</em>) The per-atom 3D atomic position vector. If not given, pos is set to [0,0,0] for all atoms.</p></li>
<li><p><strong>prop</strong> (<em>dict, optional</em>) Dictionary containing all per-atom properties to set, alternate to passing the per-atom properties in as function parameters. Included for backwards compatibility.</p></li>
<li><p><strong>**kwargs</strong> (<em>any</em>) Other keyword parameters can be given for defining extra per-atom properties.</p></li>
</ul>
<div class="nbinput docutils container">
<div class="prompt highlight-none notranslate"><div class="highlight"><pre><span></span>[2]:
</pre></div>
</div>
<div class="input_area highlight-ipython3 notranslate"><div class="highlight"><pre>
<span></span><span class="c1"># Define 10 atom system with random positions</span>
<span class="c1"># Notes: natoms inferred from first dimension of pos. Same atype assigned to all atoms</span>
<span class="n">atoms</span> <span class="o">=</span> <span class="n">am</span><span class="o">.</span><span class="n">Atoms</span><span class="p">(</span><span class="n">atype</span> <span class="o">=</span> <span class="mi">1</span><span class="p">,</span> <span class="n">pos</span> <span class="o">=</span> <span class="mi">4</span> <span class="o">*</span> <span class="n">np</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">rand</span><span class="p">(</span><span class="mi">10</span><span class="p">,</span> <span class="mi">3</span><span class="p">))</span>
<span class="nb">print</span><span class="p">(</span><span class="n">atoms</span><span class="p">)</span>
</pre></div>
</div>
</div>
<div class="nboutput nblast docutils container">
<div class="prompt empty docutils container">
</div>
<div class="output_area docutils container">
<div class="highlight"><pre>
per-atom properties = [&#39;atype&#39;, &#39;pos&#39;]
     id |   atype |  pos[0] |  pos[1] |  pos[2]
      0 |       1 |   1.010 |   1.119 |   3.554
      1 |       1 |   0.850 |   0.672 |   0.349
      2 |       1 |   3.197 |   2.323 |   2.250
      3 |       1 |   2.876 |   3.861 |   3.047
      4 |       1 |   0.937 |   2.570 |   3.987
      5 |       1 |   3.937 |   3.377 |   1.084
      6 |       1 |   2.010 |   3.565 |   2.835
      7 |       1 |   0.198 |   2.653 |   0.467
      8 |       1 |   3.588 |   1.307 |   1.997
      9 |       1 |   2.029 |   2.630 |   1.395
</pre></div></div>
</div>
</div>
<div class="section" id="2.2.-Pre-defined-attributes">
<h3>2.2. Pre-defined attributes<a class="headerlink" href="#2.2.-Pre-defined-attributes" title="Permalink to this headline">¶</a></h3>
<p>The class has a few pre-defined attributes:</p>
<ul class="simple">
<li><p><strong>natoms</strong> is the number of atoms. len(Atoms) returns the same thing.</p></li>
<li><p><strong>atypes</strong> gives a list of all unique atype values.</p></li>
<li><p><strong>natypes</strong> gives the number of unique atype values.</p></li>
</ul>
<p><em>Update version 1.3.0:</em> The way atypes and natypes are handled has changed. Backwards compatibility will be affected if previous Atoms had atype values of 0 or non-sequential atype values. The new method restricts atype values to be ≥ 1 and atypes returns all sequential integers from 1 through natypes=max(atype).</p>
<div class="nbinput docutils container">
<div class="prompt highlight-none notranslate"><div class="highlight"><pre><span></span>[3]:
</pre></div>
</div>
<div class="input_area highlight-ipython3 notranslate"><div class="highlight"><pre>
<span></span><span class="nb">print</span><span class="p">(</span><span class="s1">&#39;atoms.natoms -&gt; &#39;</span><span class="p">,</span> <span class="n">atoms</span><span class="o">.</span><span class="n">natoms</span><span class="p">)</span>
<span class="nb">print</span><span class="p">(</span><span class="s1">&#39;len(atoms) -&gt;   &#39;</span><span class="p">,</span> <span class="nb">len</span><span class="p">(</span><span class="n">atoms</span><span class="p">))</span>
<span class="nb">print</span><span class="p">(</span><span class="s1">&#39;atoms.atypes -&gt; &#39;</span><span class="p">,</span> <span class="n">atoms</span><span class="o">.</span><span class="n">atypes</span><span class="p">)</span>
<span class="nb">print</span><span class="p">(</span><span class="s1">&#39;atoms.natypes -&gt;&#39;</span><span class="p">,</span> <span class="n">atoms</span><span class="o">.</span><span class="n">natypes</span><span class="p">)</span>
</pre></div>
</div>
</div>
<div class="nboutput nblast docutils container">
<div class="prompt empty docutils container">
</div>
<div class="output_area docutils container">
<div class="highlight"><pre>
atoms.natoms -&gt;  10
len(atoms) -&gt;    10
atoms.atypes -&gt;  (1,)
atoms.natypes -&gt; 1
</pre></div></div>
</div>
</div>
</div>
<div class="section" id="3.-Per-atom-properties">
<h2>3. Per-atom properties<a class="headerlink" href="#3.-Per-atom-properties" title="Permalink to this headline">¶</a></h2>
<p>The per-atom properties of an Atoms instance can be interacted with in one of three ways:</p>
<ul class="simple">
<li><p>as attributes of the Atoms instance, i.e. atoms.myprop.</p></li>
<li><p>as items in the Atoms.view dictionary.</p></li>
<li><p>by calling the Atoms.prop() (<a class="reference external" href="#section6">Section 6</a>) or Atoms.prop_atype() (<a class="reference external" href="#section7">Section 7</a>) methods.</p></li>
</ul>
<div class="section" id="3.1.-List-assigned-per-atom-properties">
<h3>3.1. List assigned per-atom properties<a class="headerlink" href="#3.1.-List-assigned-per-atom-properties" title="Permalink to this headline">¶</a></h3>
<p>A list of all assigned per-atom properties can be retrieved using either:</p>
<ul class="simple">
<li><p>atoms.prop()</p></li>
<li><p>atoms.view.keys()</p></li>
</ul>
<div class="nbinput docutils container">
<div class="prompt highlight-none notranslate"><div class="highlight"><pre><span></span>[4]:
</pre></div>
</div>
<div class="input_area highlight-ipython3 notranslate"><div class="highlight"><pre>
<span></span><span class="nb">print</span><span class="p">(</span><span class="s1">&#39;atoms.prop() -&gt;     &#39;</span><span class="p">,</span> <span class="n">atoms</span><span class="o">.</span><span class="n">prop</span><span class="p">())</span>
<span class="nb">print</span><span class="p">(</span><span class="s1">&#39;atoms.view.keys() -&gt;&#39;</span><span class="p">,</span> <span class="n">atoms</span><span class="o">.</span><span class="n">view</span><span class="o">.</span><span class="n">keys</span><span class="p">())</span>
</pre></div>
</div>
</div>
<div class="nboutput nblast docutils container">
<div class="prompt empty docutils container">
</div>
<div class="output_area docutils container">
<div class="highlight"><pre>
atoms.prop() -&gt;      [&#39;atype&#39;, &#39;pos&#39;]
atoms.view.keys() -&gt; odict_keys([&#39;atype&#39;, &#39;pos&#39;])
</pre></div></div>
</div>
</div>
<div class="section" id="3.2.-Accessing-per-atom-properties">
<h3>3.2. Accessing per-atom properties<a class="headerlink" href="#3.2.-Accessing-per-atom-properties" title="Permalink to this headline">¶</a></h3>
<div class="nbinput docutils container">
<div class="prompt highlight-none notranslate"><div class="highlight"><pre><span></span>[5]:
</pre></div>
</div>
<div class="input_area highlight-ipython3 notranslate"><div class="highlight"><pre>
<span></span><span class="nb">print</span><span class="p">(</span><span class="s1">&#39;atoms.atype -&gt;            &#39;</span><span class="p">,</span> <span class="n">atoms</span><span class="o">.</span><span class="n">atype</span><span class="p">)</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">&quot;atoms.view[&#39;atype&#39;] -&gt;    &quot;</span><span class="p">,</span> <span class="n">atoms</span><span class="o">.</span><span class="n">view</span><span class="p">[</span><span class="s1">&#39;atype&#39;</span><span class="p">])</span>
</pre></div>
</div>
</div>
<div class="nboutput nblast docutils container">
<div class="prompt empty docutils container">
</div>
<div class="output_area docutils container">
<div class="highlight"><pre>
atoms.atype -&gt;             [1 1 1 1 1 1 1 1 1 1]
atoms.view[&#39;atype&#39;] -&gt;     [1 1 1 1 1 1 1 1 1 1]
</pre></div></div>
</div>
</div>
<div class="section" id="3.3.-Setting-values-of-existing-per-atom-properties">
<h3>3.3. Setting values of existing per-atom properties<a class="headerlink" href="#3.3.-Setting-values-of-existing-per-atom-properties" title="Permalink to this headline">¶</a></h3>
<p>The same three options can be used for setting values to existing per-atom properties.</p>
<div class="nbinput docutils container">
<div class="prompt highlight-none notranslate"><div class="highlight"><pre><span></span>[6]:
</pre></div>
</div>
<div class="input_area highlight-ipython3 notranslate"><div class="highlight"><pre>
<span></span><span class="nb">print</span><span class="p">(</span><span class="s1">&#39;setting: atoms.atype[2] = 2&#39;</span><span class="p">)</span>
<span class="n">atoms</span><span class="o">.</span><span class="n">atype</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span> <span class="o">=</span> <span class="mi">2</span>

<span class="nb">print</span><span class="p">(</span><span class="s2">&quot;setting: atoms.view[&#39;atype&#39;][5] = 2&quot;</span><span class="p">)</span>
<span class="n">atoms</span><span class="o">.</span><span class="n">view</span><span class="p">[</span><span class="s1">&#39;atype&#39;</span><span class="p">][</span><span class="mi">5</span><span class="p">]</span> <span class="o">=</span> <span class="mi">2</span>

<span class="nb">print</span><span class="p">()</span>
<span class="nb">print</span><span class="p">(</span><span class="s1">&#39;atoms.atype -&gt;&#39;</span><span class="p">,</span> <span class="n">atoms</span><span class="o">.</span><span class="n">atype</span><span class="p">)</span>
</pre></div>
</div>
</div>
<div class="nboutput nblast docutils container">
<div class="prompt empty docutils container">
</div>
<div class="output_area docutils container">
<div class="highlight"><pre>
setting: atoms.atype[2] = 2
setting: atoms.view[&#39;atype&#39;][5] = 2

atoms.atype -&gt; [1 1 2 1 1 2 1 1 1 1]
</pre></div></div>
</div>
</div>
<div class="section" id="3.4.-Assigning-new-per-atom-properties">
<h3>3.4. Assigning new per-atom properties<a class="headerlink" href="#3.4.-Assigning-new-per-atom-properties" title="Permalink to this headline">¶</a></h3>
<p>New per-atom properties can be assigned almost as easily as setting values of exising properties. The only limitations are that values must be given for all atoms and the data types and shapes must be consistent for all atoms.</p>
<p>Value setting rules:</p>
<ul class="simple">
<li><p>Values being assigned must either have no length, a length of 1, or a length of natoms.</p></li>
<li><p>If the value has no length or a length of 1, the value will be assigned to all atoms.</p></li>
<li><p>If the value as a length of natoms, each item in value will be assigned to a different atom.</p></li>
</ul>
<div class="nbinput docutils container">
<div class="prompt highlight-none notranslate"><div class="highlight"><pre><span></span>[7]:
</pre></div>
</div>
<div class="input_area highlight-ipython3 notranslate"><div class="highlight"><pre>
<span></span><span class="c1"># Assign stress as attribute (same value for all atoms)</span>
<span class="c1"># Note first dimension is 1!</span>
<span class="n">atoms</span><span class="o">.</span><span class="n">stress</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">zeros</span><span class="p">([</span><span class="mi">1</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">3</span><span class="p">])</span>

<span class="nb">print</span><span class="p">(</span><span class="s1">&#39;atoms.prop() -&gt;&#39;</span><span class="p">,</span> <span class="n">atoms</span><span class="o">.</span><span class="n">prop</span><span class="p">())</span>
<span class="nb">print</span><span class="p">()</span>

<span class="nb">print</span><span class="p">(</span><span class="s1">&#39;atoms.stress[0] -&gt;&#39;</span><span class="p">)</span>
<span class="nb">print</span><span class="p">(</span><span class="n">atoms</span><span class="o">.</span><span class="n">stress</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span>
</pre></div>
</div>
</div>
<div class="nboutput nblast docutils container">
<div class="prompt empty docutils container">
</div>
<div class="output_area docutils container">
<div class="highlight"><pre>
atoms.prop() -&gt; [&#39;atype&#39;, &#39;pos&#39;, &#39;stress&#39;]

atoms.stress[0] -&gt;
[[0. 0. 0.]
 [0. 0. 0.]
 [0. 0. 0.]]
</pre></div></div>
</div>
</div>
<div class="section" id="3.5.-Viewing-per-atom-properties">
<h3>3.5. Viewing per-atom properties<a class="headerlink" href="#3.5.-Viewing-per-atom-properties" title="Permalink to this headline">¶</a></h3>
<p><em>Updated version 1.2.7</em></p>
<p>The string representation of atoms lists all assigned per-atom properties and shows id, atype and pos values.</p>
<div class="nbinput docutils container">
<div class="prompt highlight-none notranslate"><div class="highlight"><pre><span></span>[8]:
</pre></div>
</div>
<div class="input_area highlight-ipython3 notranslate"><div class="highlight"><pre>
<span></span><span class="nb">print</span><span class="p">(</span><span class="n">atoms</span><span class="p">)</span>
</pre></div>
</div>
</div>
<div class="nboutput nblast docutils container">
<div class="prompt empty docutils container">
</div>
<div class="output_area docutils container">
<div class="highlight"><pre>
per-atom properties = [&#39;atype&#39;, &#39;pos&#39;, &#39;stress&#39;]
     id |   atype |  pos[0] |  pos[1] |  pos[2]
      0 |       1 |   1.010 |   1.119 |   3.554
      1 |       1 |   0.850 |   0.672 |   0.349
      2 |       2 |   3.197 |   2.323 |   2.250
      3 |       1 |   2.876 |   3.861 |   3.047
      4 |       1 |   0.937 |   2.570 |   3.987
      5 |       2 |   3.937 |   3.377 |   1.084
      6 |       1 |   2.010 |   3.565 |   2.835
      7 |       1 |   0.198 |   2.653 |   0.467
      8 |       1 |   3.588 |   1.307 |   1.997
      9 |       1 |   2.029 |   2.630 |   1.395
</pre></div></div>
</div>
<p>Alternatively, the atoms object can be copied into a pandas.DataFrame with the Atoms.df() method. This is convenient for viewing and analyzing all per-atom property values at once.</p>
<div class="nbinput docutils container">
<div class="prompt highlight-none notranslate"><div class="highlight"><pre><span></span>[9]:
</pre></div>
</div>
<div class="input_area highlight-ipython3 notranslate"><div class="highlight"><pre>
<span></span><span class="n">df</span> <span class="o">=</span> <span class="n">atoms</span><span class="o">.</span><span class="n">df</span><span class="p">()</span>
<span class="n">df</span>
</pre></div>
</div>
</div>
<div class="nboutput nblast docutils container">
<div class="prompt highlight-none notranslate"><div class="highlight"><pre><span></span>[9]:
</pre></div>
</div>
<div class="output_area rendered_html docutils container">
<div>
<style scoped>
    .dataframe tbody tr th:only-of-type {
        vertical-align: middle;
    }

    .dataframe tbody tr th {
        vertical-align: top;
    }

    .dataframe thead th {
        text-align: right;
    }
</style>
<table border="1" class="dataframe">
  <thead>
    <tr style="text-align: right;">
      <th></th>
      <th>atype</th>
      <th>pos[0]</th>
      <th>pos[1]</th>
      <th>pos[2]</th>
      <th>stress[0][0]</th>
      <th>stress[0][1]</th>
      <th>stress[0][2]</th>
      <th>stress[1][0]</th>
      <th>stress[1][1]</th>
      <th>stress[1][2]</th>
      <th>stress[2][0]</th>
      <th>stress[2][1]</th>
      <th>stress[2][2]</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>0</td>
      <td>1</td>
      <td>1.009574</td>
      <td>1.118980</td>
      <td>3.554220</td>
      <td>0.0</td>
      <td>0.0</td>
      <td>0.0</td>
      <td>0.0</td>
      <td>0.0</td>
      <td>0.0</td>
      <td>0.0</td>
      <td>0.0</td>
      <td>0.0</td>
    </tr>
    <tr>
      <td>1</td>
      <td>1</td>
      <td>0.850193</td>
      <td>0.672331</td>
      <td>0.349284</td>
      <td>0.0</td>
      <td>0.0</td>
      <td>0.0</td>
      <td>0.0</td>
      <td>0.0</td>
      <td>0.0</td>
      <td>0.0</td>
      <td>0.0</td>
      <td>0.0</td>
    </tr>
    <tr>
      <td>2</td>
      <td>2</td>
      <td>3.197080</td>
      <td>2.323269</td>
      <td>2.250059</td>
      <td>0.0</td>
      <td>0.0</td>
      <td>0.0</td>
      <td>0.0</td>
      <td>0.0</td>
      <td>0.0</td>
      <td>0.0</td>
      <td>0.0</td>
      <td>0.0</td>
    </tr>
    <tr>
      <td>3</td>
      <td>1</td>
      <td>2.875604</td>
      <td>3.861164</td>
      <td>3.046810</td>
      <td>0.0</td>
      <td>0.0</td>
      <td>0.0</td>
      <td>0.0</td>
      <td>0.0</td>
      <td>0.0</td>
      <td>0.0</td>
      <td>0.0</td>
      <td>0.0</td>
    </tr>
    <tr>
      <td>4</td>
      <td>1</td>
      <td>0.937406</td>
      <td>2.569794</td>
      <td>3.986789</td>
      <td>0.0</td>
      <td>0.0</td>
      <td>0.0</td>
      <td>0.0</td>
      <td>0.0</td>
      <td>0.0</td>
      <td>0.0</td>
      <td>0.0</td>
      <td>0.0</td>
    </tr>
    <tr>
      <td>5</td>
      <td>2</td>
      <td>3.937418</td>
      <td>3.376766</td>
      <td>1.084392</td>
      <td>0.0</td>
      <td>0.0</td>
      <td>0.0</td>
      <td>0.0</td>
      <td>0.0</td>
      <td>0.0</td>
      <td>0.0</td>
      <td>0.0</td>
      <td>0.0</td>
    </tr>
    <tr>
      <td>6</td>
      <td>1</td>
      <td>2.009608</td>
      <td>3.564657</td>
      <td>2.834760</td>
      <td>0.0</td>
      <td>0.0</td>
      <td>0.0</td>
      <td>0.0</td>
      <td>0.0</td>
      <td>0.0</td>
      <td>0.0</td>
      <td>0.0</td>
      <td>0.0</td>
    </tr>
    <tr>
      <td>7</td>
      <td>1</td>
      <td>0.198067</td>
      <td>2.653309</td>
      <td>0.466867</td>
      <td>0.0</td>
      <td>0.0</td>
      <td>0.0</td>
      <td>0.0</td>
      <td>0.0</td>
      <td>0.0</td>
      <td>0.0</td>
      <td>0.0</td>
      <td>0.0</td>
    </tr>
    <tr>
      <td>8</td>
      <td>1</td>
      <td>3.587661</td>
      <td>1.306515</td>
      <td>1.996816</td>
      <td>0.0</td>
      <td>0.0</td>
      <td>0.0</td>
      <td>0.0</td>
      <td>0.0</td>
      <td>0.0</td>
      <td>0.0</td>
      <td>0.0</td>
      <td>0.0</td>
    </tr>
    <tr>
      <td>9</td>
      <td>1</td>
      <td>2.029141</td>
      <td>2.630481</td>
      <td>1.395071</td>
      <td>0.0</td>
      <td>0.0</td>
      <td>0.0</td>
      <td>0.0</td>
      <td>0.0</td>
      <td>0.0</td>
      <td>0.0</td>
      <td>0.0</td>
      <td>0.0</td>
    </tr>
  </tbody>
</table>
</div></div>
</div>
<p><strong>Note</strong> that the values in the DataFrame are copies: calling Atoms.df() doubles the memory usage and changed values are not retained.</p>
<div class="nbinput docutils container">
<div class="prompt highlight-none notranslate"><div class="highlight"><pre><span></span>[10]:
</pre></div>
</div>
<div class="input_area highlight-ipython3 notranslate"><div class="highlight"><pre>
<span></span><span class="n">df</span><span class="o">.</span><span class="n">loc</span><span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="s1">&#39;atype&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="mi">3</span>
<span class="nb">print</span><span class="p">(</span><span class="n">df</span><span class="o">.</span><span class="n">atype</span><span class="o">.</span><span class="n">values</span><span class="p">)</span>
<span class="nb">print</span><span class="p">(</span><span class="n">atoms</span><span class="o">.</span><span class="n">atype</span><span class="p">)</span>
</pre></div>
</div>
</div>
<div class="nboutput nblast docutils container">
<div class="prompt empty docutils container">
</div>
<div class="output_area docutils container">
<div class="highlight"><pre>
[3 1 2 1 1 2 1 1 1 1]
[1 1 2 1 1 2 1 1 1 1]
</pre></div></div>
</div>
</div>
</div>
<div class="section" id="4.-Atoms-by-index">
<h2>4. Atoms by index<a class="headerlink" href="#4.-Atoms-by-index" title="Permalink to this headline">¶</a></h2>
<p>The Atoms class also allows for the atoms to be get/set using numpy indexing. This is useful for manipulations in how the atoms are listed and all per-atom properties for a given atom are to be retained.</p>
<p><strong>Note:</strong> If you want to access/manipulate per-atom properties of certain atoms, it is more efficient to access the properties first (as in <a class="reference external" href="#section3">Section 3</a>) then apply the slice.</p>
<div class="section" id="4.1.-Getting-by-index">
<h3>4.1. Getting by index<a class="headerlink" href="#4.1.-Getting-by-index" title="Permalink to this headline">¶</a></h3>
<p>An atoms object can be sliced using numpy indexing. This returns a new Atoms instance containing only the selected atom(s). Useful for generating subsets.</p>
<div class="nbinput docutils container">
<div class="prompt highlight-none notranslate"><div class="highlight"><pre><span></span>[11]:
</pre></div>
</div>
<div class="input_area highlight-ipython3 notranslate"><div class="highlight"><pre>
<span></span><span class="c1"># Get only the atoms with x position greater than 3</span>
<span class="n">upperatoms</span> <span class="o">=</span> <span class="n">atoms</span><span class="p">[</span><span class="n">atoms</span><span class="o">.</span><span class="n">pos</span><span class="p">[:,</span> <span class="mi">0</span><span class="p">]</span> <span class="o">&gt;</span> <span class="mi">3</span><span class="p">]</span>
<span class="nb">print</span><span class="p">(</span><span class="n">upperatoms</span><span class="p">)</span>
</pre></div>
</div>
</div>
<div class="nboutput nblast docutils container">
<div class="prompt empty docutils container">
</div>
<div class="output_area docutils container">
<div class="highlight"><pre>
per-atom properties = [&#39;atype&#39;, &#39;pos&#39;, &#39;stress&#39;]
     id |   atype |  pos[0] |  pos[1] |  pos[2]
      0 |       2 |   3.197 |   2.323 |   2.250
      1 |       2 |   3.937 |   3.377 |   1.084
      2 |       1 |   3.588 |   1.307 |   1.997
</pre></div></div>
</div>
</div>
<div class="section" id="4.2.-Setting-by-index">
<h3>4.2. Setting by index<a class="headerlink" href="#4.2.-Setting-by-index" title="Permalink to this headline">¶</a></h3>
<p>All per-atom values of a subset of Atoms can be set at once using indexing. The value being assigned must be an Atoms instance of compatible size and same per-atom properties as the Atoms instance it is being assigned to.</p>
<div class="nbinput docutils container">
<div class="prompt highlight-none notranslate"><div class="highlight"><pre><span></span>[12]:
</pre></div>
</div>
<div class="input_area highlight-ipython3 notranslate"><div class="highlight"><pre>
<span></span><span class="c1"># Copy first atom in atoms to last atom in upperatoms</span>
<span class="n">upperatoms</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span> <span class="o">=</span> <span class="n">atoms</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
<span class="nb">print</span><span class="p">(</span><span class="n">upperatoms</span><span class="p">)</span>
</pre></div>
</div>
</div>
<div class="nboutput nblast docutils container">
<div class="prompt empty docutils container">
</div>
<div class="output_area docutils container">
<div class="highlight"><pre>
per-atom properties = [&#39;atype&#39;, &#39;pos&#39;, &#39;stress&#39;]
     id |   atype |  pos[0] |  pos[1] |  pos[2]
      0 |       2 |   3.197 |   2.323 |   2.250
      1 |       2 |   3.937 |   3.377 |   1.084
      2 |       1 |   1.010 |   1.119 |   3.554
</pre></div></div>
</div>
<div class="nbinput docutils container">
<div class="prompt highlight-none notranslate"><div class="highlight"><pre><span></span>[13]:
</pre></div>
</div>
<div class="input_area highlight-ipython3 notranslate"><div class="highlight"><pre>
<span></span><span class="c1"># Swap atoms 0 and 1 in atoms.</span>
<span class="nb">print</span><span class="p">(</span><span class="n">atoms</span><span class="p">)</span>
<span class="nb">print</span><span class="p">()</span>

<span class="n">atoms</span><span class="p">[[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">]]</span> <span class="o">=</span> <span class="n">atoms</span><span class="p">[[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">0</span><span class="p">]]</span>

<span class="nb">print</span><span class="p">(</span><span class="n">atoms</span><span class="p">)</span>
</pre></div>
</div>
</div>
<div class="nboutput nblast docutils container">
<div class="prompt empty docutils container">
</div>
<div class="output_area docutils container">
<div class="highlight"><pre>
per-atom properties = [&#39;atype&#39;, &#39;pos&#39;, &#39;stress&#39;]
     id |   atype |  pos[0] |  pos[1] |  pos[2]
      0 |       1 |   1.010 |   1.119 |   3.554
      1 |       1 |   0.850 |   0.672 |   0.349
      2 |       2 |   3.197 |   2.323 |   2.250
      3 |       1 |   2.876 |   3.861 |   3.047
      4 |       1 |   0.937 |   2.570 |   3.987
      5 |       2 |   3.937 |   3.377 |   1.084
      6 |       1 |   2.010 |   3.565 |   2.835
      7 |       1 |   0.198 |   2.653 |   0.467
      8 |       1 |   3.588 |   1.307 |   1.997
      9 |       1 |   2.029 |   2.630 |   1.395

per-atom properties = [&#39;atype&#39;, &#39;pos&#39;, &#39;stress&#39;]
     id |   atype |  pos[0] |  pos[1] |  pos[2]
      0 |       1 |   0.850 |   0.672 |   0.349
      1 |       1 |   1.010 |   1.119 |   3.554
      2 |       2 |   3.197 |   2.323 |   2.250
      3 |       1 |   2.876 |   3.861 |   3.047
      4 |       1 |   0.937 |   2.570 |   3.987
      5 |       2 |   3.937 |   3.377 |   1.084
      6 |       1 |   2.010 |   3.565 |   2.835
      7 |       1 |   0.198 |   2.653 |   0.467
      8 |       1 |   3.588 |   1.307 |   1.997
      9 |       1 |   2.029 |   2.630 |   1.395
</pre></div></div>
</div>
</div>
</div>
<div class="section" id="5.-Atoms.extend()">
<h2>5. Atoms.extend()<a class="headerlink" href="#5.-Atoms.extend()" title="Permalink to this headline">¶</a></h2>
<p><em>Added version 1.2.8</em></p>
<p>The Atoms.extend method creates a new Atoms object by copying the current Atoms object and adding new atoms to it. The new atoms can either be copied from another existing Atoms object, or a specified number of ‘empty’ atoms can be added.</p>
<p>Parameters - <strong>value</strong> (<em>atomman.Atoms or int</em>) An int value will result in the atoms object being extended by that number of atoms, with all per-atom properties having default values (atype = 1, everything else = 0). For an Atoms value, the current atoms list will be extended by the correct number of atoms and all per-atom properties in value will be copied over. Any properties defined in one Atoms object and not the other will be set to default values.</p>
<p>Returns - (<em>atomman.Atoms</em>) A new Atoms object containing all atoms and properties of the current object plus the additional atoms.</p>
<p>Passing Atoms.extend() an integer will add that many empty atoms to the end of the Atoms list.</p>
<div class="nbinput docutils container">
<div class="prompt highlight-none notranslate"><div class="highlight"><pre><span></span>[14]:
</pre></div>
</div>
<div class="input_area highlight-ipython3 notranslate"><div class="highlight"><pre>
<span></span><span class="nb">print</span><span class="p">(</span><span class="n">atoms</span><span class="o">.</span><span class="n">extend</span><span class="p">(</span><span class="mi">2</span><span class="p">))</span>
</pre></div>
</div>
</div>
<div class="nboutput nblast docutils container">
<div class="prompt empty docutils container">
</div>
<div class="output_area docutils container">
<div class="highlight"><pre>
per-atom properties = [&#39;atype&#39;, &#39;pos&#39;, &#39;stress&#39;]
     id |   atype |  pos[0] |  pos[1] |  pos[2]
      0 |       1 |   0.850 |   0.672 |   0.349
      1 |       1 |   1.010 |   1.119 |   3.554
      2 |       2 |   3.197 |   2.323 |   2.250
      3 |       1 |   2.876 |   3.861 |   3.047
      4 |       1 |   0.937 |   2.570 |   3.987
      5 |       2 |   3.937 |   3.377 |   1.084
      6 |       1 |   2.010 |   3.565 |   2.835
      7 |       1 |   0.198 |   2.653 |   0.467
      8 |       1 |   3.588 |   1.307 |   1.997
      9 |       1 |   2.029 |   2.630 |   1.395
     10 |       1 |   0.000 |   0.000 |   0.000
     11 |       1 |   0.000 |   0.000 |   0.000
</pre></div></div>
</div>
<p>Passing Atoms.extend() an Atoms object will combine the two Atoms lists.</p>
<div class="nbinput docutils container">
<div class="prompt highlight-none notranslate"><div class="highlight"><pre><span></span>[15]:
</pre></div>
</div>
<div class="input_area highlight-ipython3 notranslate"><div class="highlight"><pre>
<span></span><span class="c1"># Add copies of atoms 0,1,2,3 to the end</span>
<span class="nb">print</span><span class="p">(</span><span class="n">atoms</span><span class="o">.</span><span class="n">extend</span><span class="p">(</span><span class="n">atoms</span><span class="p">[:</span><span class="mi">4</span><span class="p">]))</span>
</pre></div>
</div>
</div>
<div class="nboutput nblast docutils container">
<div class="prompt empty docutils container">
</div>
<div class="output_area docutils container">
<div class="highlight"><pre>
per-atom properties = [&#39;atype&#39;, &#39;pos&#39;, &#39;stress&#39;]
     id |   atype |  pos[0] |  pos[1] |  pos[2]
      0 |       1 |   0.850 |   0.672 |   0.349
      1 |       1 |   1.010 |   1.119 |   3.554
      2 |       2 |   3.197 |   2.323 |   2.250
      3 |       1 |   2.876 |   3.861 |   3.047
      4 |       1 |   0.937 |   2.570 |   3.987
      5 |       2 |   3.937 |   3.377 |   1.084
      6 |       1 |   2.010 |   3.565 |   2.835
      7 |       1 |   0.198 |   2.653 |   0.467
      8 |       1 |   3.588 |   1.307 |   1.997
      9 |       1 |   2.029 |   2.630 |   1.395
     10 |       1 |   0.850 |   0.672 |   0.349
     11 |       1 |   1.010 |   1.119 |   3.554
     12 |       2 |   3.197 |   2.323 |   2.250
     13 |       1 |   2.876 |   3.861 |   3.047
</pre></div></div>
</div>
</div>
<div class="section" id="6.-Atoms.prop()">
<h2>6. Atoms.prop()<a class="headerlink" href="#6.-Atoms.prop()" title="Permalink to this headline">¶</a></h2>
<p>The Atoms.prop() method offers a “safe” means of getting and setting values. It is designed with three things in mind:</p>
<ol class="arabic simple">
<li><p>All get/set actions copy values instead of references.</p></li>
<li><p>For consistency with the System.atoms_prop() method.</p></li>
<li><p>For backwards compatibility with older atomman versions.</p></li>
</ol>
<p>Parameters:</p>
<ul class="simple">
<li><p><strong>key</strong> (<em>str, optional</em>) Per-atom property name.</p></li>
<li><p><strong>index</strong> (<em>int, list, slice, optional</em>) Index of atoms.</p></li>
<li><p><strong>value</strong> (<em>any, optional</em>) Property values to assign.</p></li>
<li><p><strong>a_id</strong> (<em>int, optional</em>) Alternate name for index. Left in for backwards compatibility.</p></li>
</ul>
<p>With no arguments, prop() returns the list of assigned per-atom properties.</p>
<div class="nbinput docutils container">
<div class="prompt highlight-none notranslate"><div class="highlight"><pre><span></span>[16]:
</pre></div>
</div>
<div class="input_area highlight-ipython3 notranslate"><div class="highlight"><pre>
<span></span><span class="nb">print</span><span class="p">(</span><span class="n">atoms</span><span class="o">.</span><span class="n">prop</span><span class="p">())</span>
</pre></div>
</div>
</div>
<div class="nboutput nblast docutils container">
<div class="prompt empty docutils container">
</div>
<div class="output_area docutils container">
<div class="highlight"><pre>
[&#39;atype&#39;, &#39;pos&#39;, &#39;stress&#39;]
</pre></div></div>
</div>
<p>If the value parameter is not given, prop() will return a copy of the value associated with the key, index combination.</p>
<div class="nbinput docutils container">
<div class="prompt highlight-none notranslate"><div class="highlight"><pre><span></span>[17]:
</pre></div>
</div>
<div class="input_area highlight-ipython3 notranslate"><div class="highlight"><pre>
<span></span><span class="c1"># key by itself returns the property value</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">&quot;atoms.prop(&#39;atype&#39;) -&gt;&quot;</span><span class="p">,</span> <span class="n">atoms</span><span class="o">.</span><span class="n">prop</span><span class="p">(</span><span class="s1">&#39;atype&#39;</span><span class="p">))</span>
<span class="nb">print</span><span class="p">()</span>

<span class="c1"># index by itself returns an Atoms slice</span>
<span class="nb">print</span><span class="p">(</span><span class="s1">&#39;atoms.prop(index=slice(1,5)) -&gt;&#39;</span><span class="p">)</span>
<span class="nb">print</span><span class="p">(</span><span class="n">atoms</span><span class="o">.</span><span class="n">prop</span><span class="p">(</span><span class="n">index</span><span class="o">=</span><span class="nb">slice</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span><span class="mi">5</span><span class="p">)))</span>
<span class="nb">print</span><span class="p">()</span>

<span class="c1"># key and index returns property value(s) of specific atoms</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">&quot;atoms.prop(key=&#39;pos&#39;, index=0) -&gt;&quot;</span><span class="p">)</span>
<span class="nb">print</span><span class="p">(</span><span class="n">atoms</span><span class="o">.</span><span class="n">prop</span><span class="p">(</span><span class="n">key</span><span class="o">=</span><span class="s1">&#39;pos&#39;</span><span class="p">,</span> <span class="n">index</span><span class="o">=</span><span class="mi">0</span><span class="p">))</span>
</pre></div>
</div>
</div>
<div class="nboutput nblast docutils container">
<div class="prompt empty docutils container">
</div>
<div class="output_area docutils container">
<div class="highlight"><pre>
atoms.prop(&#39;atype&#39;) -&gt; [1 1 2 1 1 2 1 1 1 1]

atoms.prop(index=slice(1,5)) -&gt;
per-atom properties = [&#39;atype&#39;, &#39;pos&#39;, &#39;stress&#39;]
     id |   atype |  pos[0] |  pos[1] |  pos[2]
      0 |       1 |   1.010 |   1.119 |   3.554
      1 |       2 |   3.197 |   2.323 |   2.250
      2 |       1 |   2.876 |   3.861 |   3.047
      3 |       1 |   0.937 |   2.570 |   3.987

atoms.prop(key=&#39;pos&#39;, index=0) -&gt;
[0.85019265 0.67233107 0.34928439]
</pre></div></div>
</div>
<p>Values can be set to Atoms using the value parameter. Any values set are copied to the Atoms instance as opposed to assigned by reference.</p>
<div class="nbinput docutils container">
<div class="prompt highlight-none notranslate"><div class="highlight"><pre><span></span>[18]:
</pre></div>
</div>
<div class="input_area highlight-ipython3 notranslate"><div class="highlight"><pre>
<span></span><span class="c1"># Set all values of a given property</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">&quot;calling: atoms.prop(key=&#39;atype&#39;, value=7)&quot;</span><span class="p">)</span>
<span class="n">atoms</span><span class="o">.</span><span class="n">prop</span><span class="p">(</span><span class="n">key</span><span class="o">=</span><span class="s1">&#39;atype&#39;</span><span class="p">,</span> <span class="n">value</span><span class="o">=</span><span class="p">[</span><span class="mi">7</span><span class="p">])</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">&quot;atoms.prop(&#39;atype&#39;) -&gt;&quot;</span><span class="p">,</span> <span class="n">atoms</span><span class="o">.</span><span class="n">prop</span><span class="p">(</span><span class="s1">&#39;atype&#39;</span><span class="p">))</span>
<span class="nb">print</span><span class="p">()</span>

<span class="c1"># Set the value of a specific atom&#39;s property</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">&quot;calling: atoms.prop(key=&#39;atype&#39;, index=4, value=1)&quot;</span><span class="p">)</span>
<span class="n">atoms</span><span class="o">.</span><span class="n">prop</span><span class="p">(</span><span class="n">key</span><span class="o">=</span><span class="s1">&#39;atype&#39;</span><span class="p">,</span> <span class="n">index</span><span class="o">=</span><span class="mi">4</span><span class="p">,</span> <span class="n">value</span><span class="o">=</span><span class="mi">1</span><span class="p">)</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">&quot;atoms.prop(&#39;atype&#39;) -&gt;&quot;</span><span class="p">,</span> <span class="n">atoms</span><span class="o">.</span><span class="n">prop</span><span class="p">(</span><span class="s1">&#39;atype&#39;</span><span class="p">))</span>
<span class="nb">print</span><span class="p">()</span>
</pre></div>
</div>
</div>
<div class="nboutput nblast docutils container">
<div class="prompt empty docutils container">
</div>
<div class="output_area docutils container">
<div class="highlight"><pre>
calling: atoms.prop(key=&#39;atype&#39;, value=7)
atoms.prop(&#39;atype&#39;) -&gt; [7 7 7 7 7 7 7 7 7 7]

calling: atoms.prop(key=&#39;atype&#39;, index=4, value=1)
atoms.prop(&#39;atype&#39;) -&gt; [7 7 7 7 1 7 7 7 7 7]

</pre></div></div>
</div>
<div class="nbinput docutils container">
<div class="prompt highlight-none notranslate"><div class="highlight"><pre><span></span>[19]:
</pre></div>
</div>
<div class="input_area highlight-ipython3 notranslate"><div class="highlight"><pre>
<span></span><span class="c1"># Copy atom 0 to atom 9</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">&quot;calling: atoms.prop(index=9, value=atoms.prop(index=0))&quot;</span><span class="p">)</span>
<span class="n">atoms</span><span class="o">.</span><span class="n">prop</span><span class="p">(</span><span class="n">index</span><span class="o">=</span><span class="mi">9</span><span class="p">,</span> <span class="n">value</span><span class="o">=</span><span class="n">atoms</span><span class="o">.</span><span class="n">prop</span><span class="p">(</span><span class="n">index</span><span class="o">=</span><span class="mi">0</span><span class="p">))</span>
<span class="nb">print</span><span class="p">(</span><span class="n">atoms</span><span class="p">)</span>
</pre></div>
</div>
</div>
<div class="nboutput nblast docutils container">
<div class="prompt empty docutils container">
</div>
<div class="output_area docutils container">
<div class="highlight"><pre>
calling: atoms.prop(index=9, value=atoms.prop(index=0))
per-atom properties = [&#39;atype&#39;, &#39;pos&#39;, &#39;stress&#39;]
     id |   atype |  pos[0] |  pos[1] |  pos[2]
      0 |       7 |   0.850 |   0.672 |   0.349
      1 |       7 |   1.010 |   1.119 |   3.554
      2 |       7 |   3.197 |   2.323 |   2.250
      3 |       7 |   2.876 |   3.861 |   3.047
      4 |       1 |   0.937 |   2.570 |   3.987
      5 |       7 |   3.937 |   3.377 |   1.084
      6 |       7 |   2.010 |   3.565 |   2.835
      7 |       7 |   0.198 |   2.653 |   0.467
      8 |       7 |   3.588 |   1.307 |   1.997
      9 |       7 |   0.850 |   0.672 |   0.349
</pre></div></div>
</div>
<p>Demonstrate safe copy of prop() using only value parameter.</p>
<div class="nbinput docutils container">
<div class="prompt highlight-none notranslate"><div class="highlight"><pre><span></span>[20]:
</pre></div>
</div>
<div class="input_area highlight-ipython3 notranslate"><div class="highlight"><pre>
<span></span><span class="c1"># Generate atoms1 with 3 atoms (all with atype=1, pos=[0,0,0])</span>
<span class="n">atoms1</span> <span class="o">=</span> <span class="n">am</span><span class="o">.</span><span class="n">Atoms</span><span class="p">(</span><span class="n">natoms</span><span class="o">=</span><span class="mi">3</span><span class="p">)</span>
<span class="nb">print</span><span class="p">(</span><span class="s1">&#39;atoms1 -&gt;&#39;</span><span class="p">)</span>
<span class="nb">print</span><span class="p">(</span><span class="n">atoms1</span><span class="p">)</span>
</pre></div>
</div>
</div>
<div class="nboutput nblast docutils container">
<div class="prompt empty docutils container">
</div>
<div class="output_area docutils container">
<div class="highlight"><pre>
atoms1 -&gt;
per-atom properties = [&#39;atype&#39;, &#39;pos&#39;]
     id |   atype |  pos[0] |  pos[1] |  pos[2]
      0 |       1 |   0.000 |   0.000 |   0.000
      1 |       1 |   0.000 |   0.000 |   0.000
      2 |       1 |   0.000 |   0.000 |   0.000
</pre></div></div>
</div>
<div class="nbinput docutils container">
<div class="prompt highlight-none notranslate"><div class="highlight"><pre><span></span>[21]:
</pre></div>
</div>
<div class="input_area highlight-ipython3 notranslate"><div class="highlight"><pre>
<span></span><span class="c1"># Directly setting atoms2 = atoms1 makes them point to the same reference</span>
<span class="nb">print</span><span class="p">(</span><span class="s1">&#39;setting atoms2 = atoms1&#39;</span><span class="p">)</span>
<span class="n">atoms2</span> <span class="o">=</span> <span class="n">atoms1</span>

<span class="c1"># Changing atoms2 changes atoms1</span>
<span class="nb">print</span><span class="p">(</span><span class="s1">&#39;setting: atoms2.atype = 2&#39;</span><span class="p">)</span>
<span class="n">atoms2</span><span class="o">.</span><span class="n">atype</span> <span class="o">=</span> <span class="mi">2</span>

<span class="nb">print</span><span class="p">(</span><span class="s1">&#39;atoms1 -&gt;&#39;</span><span class="p">)</span>
<span class="nb">print</span><span class="p">(</span><span class="n">atoms1</span><span class="p">)</span>
</pre></div>
</div>
</div>
<div class="nboutput nblast docutils container">
<div class="prompt empty docutils container">
</div>
<div class="output_area docutils container">
<div class="highlight"><pre>
setting atoms2 = atoms1
setting: atoms2.atype = 2
atoms1 -&gt;
per-atom properties = [&#39;atype&#39;, &#39;pos&#39;]
     id |   atype |  pos[0] |  pos[1] |  pos[2]
      0 |       2 |   0.000 |   0.000 |   0.000
      1 |       2 |   0.000 |   0.000 |   0.000
      2 |       2 |   0.000 |   0.000 |   0.000
</pre></div></div>
</div>
<div class="nbinput docutils container">
<div class="prompt highlight-none notranslate"><div class="highlight"><pre><span></span>[22]:
</pre></div>
</div>
<div class="input_area highlight-ipython3 notranslate"><div class="highlight"><pre>
<span></span><span class="c1"># Seting atoms3 to atoms1 using prop() copies values *not* reference.</span>
<span class="nb">print</span><span class="p">(</span><span class="s1">&#39;setting: atoms3 = am.Atoms(natoms=3)&#39;</span><span class="p">)</span>
<span class="n">atoms3</span> <span class="o">=</span> <span class="n">am</span><span class="o">.</span><span class="n">Atoms</span><span class="p">(</span><span class="n">natoms</span><span class="o">=</span><span class="mi">3</span><span class="p">)</span>
<span class="nb">print</span><span class="p">(</span><span class="s1">&#39;calling: atoms3.prop(value=atoms1)&#39;</span><span class="p">)</span>
<span class="n">atoms3</span><span class="o">.</span><span class="n">prop</span><span class="p">(</span><span class="n">value</span><span class="o">=</span><span class="n">atoms1</span><span class="p">)</span>
<span class="nb">print</span><span class="p">(</span><span class="s1">&#39;atoms3 -&gt;&#39;</span><span class="p">)</span>
<span class="nb">print</span><span class="p">(</span><span class="n">atoms3</span><span class="p">)</span>
<span class="c1"># Changing atoms3 does not change atoms1</span>
<span class="nb">print</span><span class="p">(</span><span class="s1">&#39;setting: atoms3.atype = 3&#39;</span><span class="p">)</span>
<span class="n">atoms3</span><span class="o">.</span><span class="n">atype</span> <span class="o">=</span> <span class="mi">3</span>

<span class="nb">print</span><span class="p">(</span><span class="s1">&#39;atoms1 -&gt;&#39;</span><span class="p">)</span>
<span class="nb">print</span><span class="p">(</span><span class="n">atoms1</span><span class="p">)</span>
<span class="nb">print</span><span class="p">(</span><span class="s1">&#39;atoms3 -&gt;&#39;</span><span class="p">)</span>
<span class="nb">print</span><span class="p">(</span><span class="n">atoms3</span><span class="p">)</span>
</pre></div>
</div>
</div>
<div class="nboutput nblast docutils container">
<div class="prompt empty docutils container">
</div>
<div class="output_area docutils container">
<div class="highlight"><pre>
setting: atoms3 = am.Atoms(natoms=3)
calling: atoms3.prop(value=atoms1)
atoms3 -&gt;
per-atom properties = [&#39;atype&#39;, &#39;pos&#39;]
     id |   atype |  pos[0] |  pos[1] |  pos[2]
      0 |       2 |   0.000 |   0.000 |   0.000
      1 |       2 |   0.000 |   0.000 |   0.000
      2 |       2 |   0.000 |   0.000 |   0.000
setting: atoms3.atype = 3
atoms1 -&gt;
per-atom properties = [&#39;atype&#39;, &#39;pos&#39;]
     id |   atype |  pos[0] |  pos[1] |  pos[2]
      0 |       2 |   0.000 |   0.000 |   0.000
      1 |       2 |   0.000 |   0.000 |   0.000
      2 |       2 |   0.000 |   0.000 |   0.000
atoms3 -&gt;
per-atom properties = [&#39;atype&#39;, &#39;pos&#39;]
     id |   atype |  pos[0] |  pos[1] |  pos[2]
      0 |       3 |   0.000 |   0.000 |   0.000
      1 |       3 |   0.000 |   0.000 |   0.000
      2 |       3 |   0.000 |   0.000 |   0.000
</pre></div></div>
</div>
</div>
<div class="section" id="7.-Atoms.prop_atype()">
<h2>7. Atoms.prop_atype()<a class="headerlink" href="#7.-Atoms.prop_atype()" title="Permalink to this headline">¶</a></h2>
<p><em>Added version 1.3.0</em></p>
<p>prop_atype() is a convenience method allowing for property values to be assigned to the atoms based on the atom’s corresponding atype values.</p>
<p>Parameters</p>
<ul class="simple">
<li><p><strong>key</strong> (<em>str</em>) Per-atom property name.</p></li>
<li><p><strong>value</strong> (<em>list, any</em>) Property value(s) to assign. If atype is not given, this should be an object of length Atoms.natypes. Otherwise, should be a single per-atom value.</p></li>
<li><p><strong>atype</strong> (<em>int, optional</em>) A specific atype to assign value to.</p></li>
</ul>
<div class="nbinput docutils container">
<div class="prompt highlight-none notranslate"><div class="highlight"><pre><span></span>[23]:
</pre></div>
</div>
<div class="input_area highlight-ipython3 notranslate"><div class="highlight"><pre>
<span></span><span class="c1"># Generate atoms with 10 atoms and two atom types</span>
<span class="n">atoms</span> <span class="o">=</span> <span class="n">am</span><span class="o">.</span><span class="n">Atoms</span><span class="p">(</span><span class="n">atype</span><span class="o">=</span><span class="p">[</span><span class="mi">1</span><span class="p">,</span><span class="mi">1</span><span class="p">,</span><span class="mi">1</span><span class="p">,</span><span class="mi">2</span><span class="p">,</span><span class="mi">2</span><span class="p">,</span><span class="mi">2</span><span class="p">,</span><span class="mi">1</span><span class="p">,</span><span class="mi">1</span><span class="p">,</span><span class="mi">1</span><span class="p">,</span><span class="mi">2</span><span class="p">])</span>
<span class="nb">print</span><span class="p">(</span><span class="s1">&#39;atoms -&gt;&#39;</span><span class="p">)</span>
<span class="nb">print</span><span class="p">(</span><span class="n">atoms</span><span class="p">)</span>
</pre></div>
</div>
</div>
<div class="nboutput nblast docutils container">
<div class="prompt empty docutils container">
</div>
<div class="output_area docutils container">
<div class="highlight"><pre>
atoms -&gt;
per-atom properties = [&#39;atype&#39;, &#39;pos&#39;]
     id |   atype |  pos[0] |  pos[1] |  pos[2]
      0 |       1 |   0.000 |   0.000 |   0.000
      1 |       1 |   0.000 |   0.000 |   0.000
      2 |       1 |   0.000 |   0.000 |   0.000
      3 |       2 |   0.000 |   0.000 |   0.000
      4 |       2 |   0.000 |   0.000 |   0.000
      5 |       2 |   0.000 |   0.000 |   0.000
      6 |       1 |   0.000 |   0.000 |   0.000
      7 |       1 |   0.000 |   0.000 |   0.000
      8 |       1 |   0.000 |   0.000 |   0.000
      9 |       2 |   0.000 |   0.000 |   0.000
</pre></div></div>
</div>
<div class="nbinput docutils container">
<div class="prompt highlight-none notranslate"><div class="highlight"><pre><span></span>[24]:
</pre></div>
</div>
<div class="input_area highlight-ipython3 notranslate"><div class="highlight"><pre>
<span></span><span class="c1"># Assign charges to the atoms based on atom type</span>
<span class="n">atoms</span><span class="o">.</span><span class="n">prop_atype</span><span class="p">(</span><span class="s1">&#39;charge&#39;</span><span class="p">,</span> <span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">])</span>
<span class="n">atoms</span><span class="o">.</span><span class="n">df</span><span class="p">()</span>
</pre></div>
</div>
</div>
<div class="nboutput nblast docutils container">
<div class="prompt highlight-none notranslate"><div class="highlight"><pre><span></span>[24]:
</pre></div>
</div>
<div class="output_area rendered_html docutils container">
<div>
<style scoped>
    .dataframe tbody tr th:only-of-type {
        vertical-align: middle;
    }

    .dataframe tbody tr th {
        vertical-align: top;
    }

    .dataframe thead th {
        text-align: right;
    }
</style>
<table border="1" class="dataframe">
  <thead>
    <tr style="text-align: right;">
      <th></th>
      <th>atype</th>
      <th>pos[0]</th>
      <th>pos[1]</th>
      <th>pos[2]</th>
      <th>charge</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>0</td>
      <td>1</td>
      <td>0.0</td>
      <td>0.0</td>
      <td>0.0</td>
      <td>-1</td>
    </tr>
    <tr>
      <td>1</td>
      <td>1</td>
      <td>0.0</td>
      <td>0.0</td>
      <td>0.0</td>
      <td>-1</td>
    </tr>
    <tr>
      <td>2</td>
      <td>1</td>
      <td>0.0</td>
      <td>0.0</td>
      <td>0.0</td>
      <td>-1</td>
    </tr>
    <tr>
      <td>3</td>
      <td>2</td>
      <td>0.0</td>
      <td>0.0</td>
      <td>0.0</td>
      <td>1</td>
    </tr>
    <tr>
      <td>4</td>
      <td>2</td>
      <td>0.0</td>
      <td>0.0</td>
      <td>0.0</td>
      <td>1</td>
    </tr>
    <tr>
      <td>5</td>
      <td>2</td>
      <td>0.0</td>
      <td>0.0</td>
      <td>0.0</td>
      <td>1</td>
    </tr>
    <tr>
      <td>6</td>
      <td>1</td>
      <td>0.0</td>
      <td>0.0</td>
      <td>0.0</td>
      <td>-1</td>
    </tr>
    <tr>
      <td>7</td>
      <td>1</td>
      <td>0.0</td>
      <td>0.0</td>
      <td>0.0</td>
      <td>-1</td>
    </tr>
    <tr>
      <td>8</td>
      <td>1</td>
      <td>0.0</td>
      <td>0.0</td>
      <td>0.0</td>
      <td>-1</td>
    </tr>
    <tr>
      <td>9</td>
      <td>2</td>
      <td>0.0</td>
      <td>0.0</td>
      <td>0.0</td>
      <td>1</td>
    </tr>
  </tbody>
</table>
</div></div>
</div>
<div class="nbinput docutils container">
<div class="prompt highlight-none notranslate"><div class="highlight"><pre><span></span>[25]:
</pre></div>
</div>
<div class="input_area highlight-ipython3 notranslate"><div class="highlight"><pre>
<span></span><span class="c1"># Change the charges for only atoms with atype of 2</span>
<span class="n">atoms</span><span class="o">.</span><span class="n">prop_atype</span><span class="p">(</span><span class="s1">&#39;charge&#39;</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="n">atype</span><span class="o">=</span><span class="mi">2</span><span class="p">)</span>
<span class="n">atoms</span><span class="o">.</span><span class="n">df</span><span class="p">()</span>
</pre></div>
</div>
</div>
<div class="nboutput nblast docutils container">
<div class="prompt highlight-none notranslate"><div class="highlight"><pre><span></span>[25]:
</pre></div>
</div>
<div class="output_area rendered_html docutils container">
<div>
<style scoped>
    .dataframe tbody tr th:only-of-type {
        vertical-align: middle;
    }

    .dataframe tbody tr th {
        vertical-align: top;
    }

    .dataframe thead th {
        text-align: right;
    }
</style>
<table border="1" class="dataframe">
  <thead>
    <tr style="text-align: right;">
      <th></th>
      <th>atype</th>
      <th>pos[0]</th>
      <th>pos[1]</th>
      <th>pos[2]</th>
      <th>charge</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>0</td>
      <td>1</td>
      <td>0.0</td>
      <td>0.0</td>
      <td>0.0</td>
      <td>-1</td>
    </tr>
    <tr>
      <td>1</td>
      <td>1</td>
      <td>0.0</td>
      <td>0.0</td>
      <td>0.0</td>
      <td>-1</td>
    </tr>
    <tr>
      <td>2</td>
      <td>1</td>
      <td>0.0</td>
      <td>0.0</td>
      <td>0.0</td>
      <td>-1</td>
    </tr>
    <tr>
      <td>3</td>
      <td>2</td>
      <td>0.0</td>
      <td>0.0</td>
      <td>0.0</td>
      <td>0</td>
    </tr>
    <tr>
      <td>4</td>
      <td>2</td>
      <td>0.0</td>
      <td>0.0</td>
      <td>0.0</td>
      <td>0</td>
    </tr>
    <tr>
      <td>5</td>
      <td>2</td>
      <td>0.0</td>
      <td>0.0</td>
      <td>0.0</td>
      <td>0</td>
    </tr>
    <tr>
      <td>6</td>
      <td>1</td>
      <td>0.0</td>
      <td>0.0</td>
      <td>0.0</td>
      <td>-1</td>
    </tr>
    <tr>
      <td>7</td>
      <td>1</td>
      <td>0.0</td>
      <td>0.0</td>
      <td>0.0</td>
      <td>-1</td>
    </tr>
    <tr>
      <td>8</td>
      <td>1</td>
      <td>0.0</td>
      <td>0.0</td>
      <td>0.0</td>
      <td>-1</td>
    </tr>
    <tr>
      <td>9</td>
      <td>2</td>
      <td>0.0</td>
      <td>0.0</td>
      <td>0.0</td>
      <td>0</td>
    </tr>
  </tbody>
</table>
</div></div>
</div>
</div>
<div class="section" id="8.-Atoms.model()">
<h2>8. Atoms.model()<a class="headerlink" href="#8.-Atoms.model()" title="Permalink to this headline">¶</a></h2>
<p><em>Added version 1.2.7</em></p>
<p>A JSON/XML equivalent data model representation of the Atoms object can be generated using the model() method.</p>
<p>Parameters</p>
<ul class="simple">
<li><p><strong>prop_name</strong> (<em>list, optional</em>) The Atoms properties to include. If neither prop_name nor prop_unit are given, all system properties will be included.</p></li>
<li><p><strong>unit</strong> (<em>list, optional</em>) Lists the units for each prop_name as stored in the table. For a value of None, no conversion will be performed for that property. If neither unit nor prop_units given, pos will be given in Angstroms and all other values will not be converted.</p></li>
<li><p><strong>prop_unit</strong> (<em>dict, optional</em>) Dictionary where the keys are the property keys to include, and the values are units to use. If neither unit nor prop_units given, pos will be given in Angstroms and all other values will not be converted.</p></li>
</ul>
<p>Returns</p>
<ul class="simple">
<li><p>(<em>DataModelDict.DataModelDict</em>) A JSON/XML data model for the current Atoms object.</p></li>
</ul>
<div class="nbinput docutils container">
<div class="prompt highlight-none notranslate"><div class="highlight"><pre><span></span>[26]:
</pre></div>
</div>
<div class="input_area highlight-ipython3 notranslate"><div class="highlight"><pre>
<span></span><span class="n">model</span> <span class="o">=</span> <span class="n">atoms</span><span class="o">.</span><span class="n">model</span><span class="p">()</span>
<span class="nb">print</span><span class="p">(</span><span class="n">model</span><span class="o">.</span><span class="n">json</span><span class="p">())</span>
<span class="nb">print</span><span class="p">()</span>
<span class="nb">print</span><span class="p">(</span><span class="n">model</span><span class="o">.</span><span class="n">xml</span><span class="p">())</span>
</pre></div>
</div>
</div>
<div class="nboutput nblast docutils container">
<div class="prompt empty docutils container">
</div>
<div class="output_area docutils container">
<div class="highlight"><pre>
{&#34;atoms&#34;: {&#34;natoms&#34;: 10, &#34;property&#34;: [{&#34;name&#34;: &#34;atype&#34;, &#34;data&#34;: {&#34;value&#34;: [1, 1, 1, 2, 2, 2, 1, 1, 1, 2]}}, {&#34;name&#34;: &#34;pos&#34;, &#34;data&#34;: {&#34;value&#34;: [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], &#34;shape&#34;: [10, 3], &#34;unit&#34;: &#34;angstrom&#34;}}, {&#34;name&#34;: &#34;charge&#34;, &#34;data&#34;: {&#34;value&#34;: [-1, -1, -1, 0, 0, 0, -1, -1, -1, 0]}}]}}

&lt;?xml version=&#34;1.0&#34; encoding=&#34;utf-8&#34;?&gt;
&lt;atoms&gt;&lt;natoms&gt;10&lt;/natoms&gt;&lt;property&gt;&lt;name&gt;atype&lt;/name&gt;&lt;data&gt;&lt;value&gt;1&lt;/value&gt;&lt;value&gt;1&lt;/value&gt;&lt;value&gt;1&lt;/value&gt;&lt;value&gt;2&lt;/value&gt;&lt;value&gt;2&lt;/value&gt;&lt;value&gt;2&lt;/value&gt;&lt;value&gt;1&lt;/value&gt;&lt;value&gt;1&lt;/value&gt;&lt;value&gt;1&lt;/value&gt;&lt;value&gt;2&lt;/value&gt;&lt;/data&gt;&lt;/property&gt;&lt;property&gt;&lt;name&gt;pos&lt;/name&gt;&lt;data&gt;&lt;value&gt;0.0&lt;/value&gt;&lt;value&gt;0.0&lt;/value&gt;&lt;value&gt;0.0&lt;/value&gt;&lt;value&gt;0.0&lt;/value&gt;&lt;value&gt;0.0&lt;/value&gt;&lt;value&gt;0.0&lt;/value&gt;&lt;value&gt;0.0&lt;/value&gt;&lt;value&gt;0.0&lt;/value&gt;&lt;value&gt;0.0&lt;/value&gt;&lt;value&gt;0.0&lt;/value&gt;&lt;value&gt;0.0&lt;/value&gt;&lt;value&gt;0.0&lt;/value&gt;&lt;value&gt;0.0&lt;/value&gt;&lt;value&gt;0.0&lt;/value&gt;&lt;value&gt;0.0&lt;/value&gt;&lt;value&gt;0.0&lt;/value&gt;&lt;value&gt;0.0&lt;/value&gt;&lt;value&gt;0.0&lt;/value&gt;&lt;value&gt;0.0&lt;/value&gt;&lt;value&gt;0.0&lt;/value&gt;&lt;value&gt;0.0&lt;/value&gt;&lt;value&gt;0.0&lt;/value&gt;&lt;value&gt;0.0&lt;/value&gt;&lt;value&gt;0.0&lt;/value&gt;&lt;value&gt;0.0&lt;/value&gt;&lt;value&gt;0.0&lt;/value&gt;&lt;value&gt;0.0&lt;/value&gt;&lt;value&gt;0.0&lt;/value&gt;&lt;value&gt;0.0&lt;/value&gt;&lt;value&gt;0.0&lt;/value&gt;&lt;shape&gt;10&lt;/shape&gt;&lt;shape&gt;3&lt;/shape&gt;&lt;unit&gt;angstrom&lt;/unit&gt;&lt;/data&gt;&lt;/property&gt;&lt;property&gt;&lt;name&gt;charge&lt;/name&gt;&lt;data&gt;&lt;value&gt;-1&lt;/value&gt;&lt;value&gt;-1&lt;/value&gt;&lt;value&gt;-1&lt;/value&gt;&lt;value&gt;0&lt;/value&gt;&lt;value&gt;0&lt;/value&gt;&lt;value&gt;0&lt;/value&gt;&lt;value&gt;-1&lt;/value&gt;&lt;value&gt;-1&lt;/value&gt;&lt;value&gt;-1&lt;/value&gt;&lt;value&gt;0&lt;/value&gt;&lt;/data&gt;&lt;/property&gt;&lt;/atoms&gt;
</pre></div></div>
</div>
<p>Any stored model information can then be reloaded in as a new Atoms object by passing the ‘model’ parameter to the class initializer.</p>
<div class="nbinput docutils container">
<div class="prompt highlight-none notranslate"><div class="highlight"><pre><span></span>[27]:
</pre></div>
</div>
<div class="input_area highlight-ipython3 notranslate"><div class="highlight"><pre>
<span></span><span class="nb">print</span><span class="p">(</span><span class="n">am</span><span class="o">.</span><span class="n">Atoms</span><span class="p">(</span><span class="n">model</span><span class="o">=</span><span class="n">model</span><span class="p">))</span>
</pre></div>
</div>
</div>
<div class="nboutput nblast docutils container">
<div class="prompt empty docutils container">
</div>
<div class="output_area docutils container">
<div class="highlight"><pre>
per-atom properties = [&#39;atype&#39;, &#39;pos&#39;, &#39;charge&#39;]
     id |   atype |  pos[0] |  pos[1] |  pos[2]
      0 |       1 |   0.000 |   0.000 |   0.000
      1 |       1 |   0.000 |   0.000 |   0.000
      2 |       1 |   0.000 |   0.000 |   0.000
      3 |       2 |   0.000 |   0.000 |   0.000
      4 |       2 |   0.000 |   0.000 |   0.000
      5 |       2 |   0.000 |   0.000 |   0.000
      6 |       1 |   0.000 |   0.000 |   0.000
      7 |       1 |   0.000 |   0.000 |   0.000
      8 |       1 |   0.000 |   0.000 |   0.000
      9 |       2 |   0.000 |   0.000 |   0.000
</pre></div></div>
</div>
</div>
</div>


          </div>
        </div>
      </div>
      <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
        <div class="sphinxsidebarwrapper">
  <h3><a href="../index.html">Table of Contents</a></h3>
  <ul>
<li><a class="reference internal" href="#">Introduction to atomman: Atoms class</a><ul>
<li><a class="reference internal" href="#1.-Introduction">1. Introduction</a></li>
<li><a class="reference internal" href="#2.-Basics">2. Basics</a><ul>
<li><a class="reference internal" href="#2.1.-Initialization">2.1. Initialization</a></li>
<li><a class="reference internal" href="#2.2.-Pre-defined-attributes">2.2. Pre-defined attributes</a></li>
</ul>
</li>
<li><a class="reference internal" href="#3.-Per-atom-properties">3. Per-atom properties</a><ul>
<li><a class="reference internal" href="#3.1.-List-assigned-per-atom-properties">3.1. List assigned per-atom properties</a></li>
<li><a class="reference internal" href="#3.2.-Accessing-per-atom-properties">3.2. Accessing per-atom properties</a></li>
<li><a class="reference internal" href="#3.3.-Setting-values-of-existing-per-atom-properties">3.3. Setting values of existing per-atom properties</a></li>
<li><a class="reference internal" href="#3.4.-Assigning-new-per-atom-properties">3.4. Assigning new per-atom properties</a></li>
<li><a class="reference internal" href="#3.5.-Viewing-per-atom-properties">3.5. Viewing per-atom properties</a></li>
</ul>
</li>
<li><a class="reference internal" href="#4.-Atoms-by-index">4. Atoms by index</a><ul>
<li><a class="reference internal" href="#4.1.-Getting-by-index">4.1. Getting by index</a></li>
<li><a class="reference internal" href="#4.2.-Setting-by-index">4.2. Setting by index</a></li>
</ul>
</li>
<li><a class="reference internal" href="#5.-Atoms.extend()">5. Atoms.extend()</a></li>
<li><a class="reference internal" href="#6.-Atoms.prop()">6. Atoms.prop()</a></li>
<li><a class="reference internal" href="#7.-Atoms.prop_atype()">7. Atoms.prop_atype()</a></li>
<li><a class="reference internal" href="#8.-Atoms.model()">8. Atoms.model()</a></li>
</ul>
</li>
</ul>

  <h4>Previous topic</h4>
  <p class="topless"><a href="1.1._Box_class.html"
                        title="previous chapter">Introduction to atomman: Box class</a></p>
  <h4>Next topic</h4>
  <p class="topless"><a href="1.3._System_class.html"
                        title="next chapter">Introduction to atomman: System class</a></p>
        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="1.3._System_class.html" title="Introduction to atomman: System class"
             >next</a> |</li>
        <li class="right" >
          <a href="1.1._Box_class.html" title="Introduction to atomman: Box class"
             >previous</a> |</li>
        <li class="nav-item nav-item-0"><a href="../index.html">atomman 1.4.0 documentation</a> &#187;</li>
          <li class="nav-item nav-item-1"><a href="index.html" >Tutorials</a> &#187;</li> 
      </ul>
    </div>
    <div class="footer" role="contentinfo">
      Created using <a href="http://sphinx-doc.org/">Sphinx</a> 2.2.0.
    </div>
  </body>
</html>